import redis


class RedisConn:
    def __init__(self) -> None:
        self.r = redis.Redis()

    # 字符串的添加
    def str_add(self, key, value, time=0):
        if time == 0:
            self.r.set(key, value)
        else:
            self.r.setex(key, time, value)

    # 字符串获取
    def str_get(self, key):
        value = self.r.get(key)
        if value:
            value = value.decode()
        return value

    #删除
    def str_del(self,key):
        return self.r.delete(key)


r = RedisConn()
